<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/11/23
  Time: 11:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<h>
<head>
    <title>主页面</title>
    <style>
        table, tr, td, th {
            border: 1px solid black;
            padding: 8px 1em;
            border-collapse: collapse;
            text-align: center;
        }
        table {
            width: 100%;
        }
        h3 {
            text-align: center;
            margin-top: 8px;
            margin-left: 200px;
        }
        header {
            display: grid;
            grid-template-columns: 1fr auto;
        }
        header span {
            padding: 2em 2em;
        }
        input {
            width: 250px;
            height: 25px;
        }
    </style>
</head>
    <header>
    <h3>余文乐手机管理系统</h3>

    <span>
        <c:if test="${empty sessionScope.account}">
            <a href="${pageContext.request.contextPath}/phone/login">登录</a>
            ||
            <a href="${pageContext.request.contextPath}/phone/regist">注册</a>
        </c:if>

         <c:if test="${sessionScope.account != null}">
             欢迎您：${account.username}
             <a href="${pageContext.request.contextPath}/phone/logout">注销</a>
         </c:if>
    </span>
    </header>

    <div>
        <form action="${r}/phone/vague">
            <input name="condition" placeholder="查询条件（手机名称或手机产地）">
            <button>搜索</button>

            <c:if test="${sessionScope.account != null}">
                <a href="${pageContext.request.contextPath}/phone/add" style="margin-left: 900px">添加页面</a>
            </c:if>
        </form>
    </div>

    <div>
        <form action="${r}/phone/two">
            <input name="condition1" placeholder="请输入查询条件（手机价格）">
            -
            <input name="condition2" placeholder="请输入查询条件（手机价格）">
            <button>搜索</button>
        </form>
    </div>

    <table>
        <tr>
            <th>手机编号</th>
            <th>手机名称</th>
            <th>手机价格</th>
            <th>手机型号</th>
            <th>手机颜色</th>
            <th>手机产地</th>
            <th>生产日期</th>
            <%
                if (session.getAttribute("account") != null) {
            %>
            <th>操作功能</th>
            <%
                }
            %>
        </tr>

        <c:forEach var="phone" items="${iphone}">
            <tr>
                <td>${phone.id}</td>
                <td>${phone.name}</td>
                <td>${phone.price}</td>
                <td>${phone.model}</td>
                <td>${phone.color}</td>
                <td>${phone.origin}</td>
                <td>${phone.time}</td>
                <c:if test="${sessionScope.account != null}">
                <td>
                    <a href="${pageContext.request.contextPath}/phone/del?id=${phone.id}">删除</a>
                    <a href="${pageContext.request.contextPath}/phone/update?id=${phone.id}">修改</a>
                </td>
                </c:if>
            </tr>
        </c:forEach>
    </table>
</body>
</html>